﻿<DemoPageSectionComponent Id="Editors-ComboBox-DropDownWidth" ShowSizeMode="true">
    <ChildContentWithParameters Context="Params">
        @inject NwindDataService NwindDataService

        <div class="row cw-480">
            <div class="col-md-6">
                <label for="cbFirstName" class="demo-text mb-1">
                    First Name
                </label>
                <DxComboBox Data="@Data"
                            TextFieldName="@nameof(Employee.FirstName)"
                            @bind-Value="@SelectedEmployee"
                            SizeMode="Params.SizeMode"
                            DropDownWidthMode="DropDownWidthMode"
                            InputId="cbFirstName" />
            </div>
            <div class="col-md-6">
                <label for="cbEmployee" class="demo-text mb-1">
                    Employee
                </label>
                <DxComboBox Data="@Data"
                            TextFieldName="@nameof(Employee.Text)"
                            @bind-Value="@SelectedEmployee1"
                            SizeMode="Params.SizeMode"
                            DropDownWidthMode="DropDownWidthMode"
                            InputId="cbEmployee"/>
            </div>
        </div>
    </ChildContentWithParameters>

    <OptionsContent>
        <OptionComboBox Label="Drop Down Width Mode:"
                         Data="@(Enum.GetNames(typeof(DropDownWidthMode)))"
                         Value="@(DropDownWidthMode.ToString())"
                         ValueChanged="@((string selectedItem) => { DropDownWidthMode = Enum.Parse<DropDownWidthMode>(selectedItem); })" />
    </OptionsContent>


    @code {
        IEnumerable<Employee> Data { get; set; }

        Employee SelectedEmployee { get; set; }
        Employee SelectedEmployee1 { get; set; }
        DropDownWidthMode DropDownWidthMode { get; set; } = DropDownWidthMode.ContentOrEditorWidth;

        protected override async Task OnInitializedAsync() {
            Data = await NwindDataService.GetEmployeesAsync();
            SelectedEmployee = Data.FirstOrDefault();
            SelectedEmployee1 = Data.FirstOrDefault();
        }
    }
</DemoPageSectionComponent>
